
package validator;

import Errors.ErrorInformation.ERRORS;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.StringTokenizer;
import readers.Reader;

/**
 * This checks whether a teacher exists
 * @author Chris
 */
public class validWord extends validator {
    public validWord() { err = ERRORS.VALID; }
    
    public boolean isValid(String word) {
        if(word == null) {
            err = ERRORS.INVALID_GROUP;
            return false;
        }
        try {
            String line;
            BufferedReader br = new BufferedReader(new FileReader(Reader.readLocation + "wordlist.txt"));
            
            while((line = br.readLine()) != null) {
                StringTokenizer st = new StringTokenizer(line);
                if(st.countTokens() == 1)
                    if(word.equals(st.nextToken())) {
                        br.close();
                        err = ERRORS.VALID;
                        return true;
                    }
            }
            br.close();
        }
        catch(Exception ex){
            err = ERRORS.INVALID_GROUP;
            return false;
        }
        
        err = ERRORS.INVALID_GROUP;
        return false;
    }
}
